﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;

namespace FileBrowser.Model
{
    public abstract class IData
    {
        public enum Type
        {
            File,
            Folder
        };
        
        //public int customType { get; set; }
        public IData Self { get { return this; } }
        private CollectionViewSource _PreviewItems = null;
        public CollectionViewSource PreviewItems
        {
            get
            {
               
                //if(this.getType() == Type.File) return null;
                if (_PreviewItems != null)
                    return _PreviewItems;
                else
                {
                    _PreviewItems = new CollectionViewSource();
                    var tmp = new ObservableCollection<IData>();
                    tmp.Add(this);
                    int i = 1;
                    foreach (IData id in this.getItems())
                    {
                        if (id.getType() == Type.File)
                        {
                            tmp.Add(id);
                            i++;
                            if (i == 4)
                                break;
                        }
                    }
                    _PreviewItems.Source = tmp;
                    Debug.WriteLine(Name + "\t get Preview Items called > "+tmp);
                    return _PreviewItems;
                }
            }

        }

        public int Height { get; set; }
        public int Width { get; set; }
        protected string _Name { get; set; }
        public string Name { 
            get {return _Name;}
            set { _Name = value; setName(value); }
        }
        public ImageSource DataIcon { get; set; }
        
        protected abstract void setName(String name);

        //public Grid graphicalRepresentation { get; set; }

        /// <summary>
        /// return the type of data. (File or Folder)
        /// </summary>
        /// <returns>IData.Type</returns>
        public abstract Type getType();
        
        /// <summary>
        /// get all files and subfolder if this is a folder otherwise return null
        /// </summary>
        /// <returns></returns>
        public abstract List<IData> getItems();

        public String getID()
        {
            if (getType() == Type.File)
                return "1_" + Name;
            else
                return "0_" + Name;
        }
        
    }
}
